package com.xxx.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *拦截器
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断域中是否有用户的uid有则说明已经登录
        Object uid = request.getSession().getAttribute("uid");
        if(uid==null){//未登录 跳到登录页面  重定向
            response.sendRedirect("/web/login.html");
            return false;
        }
        //已登录 放行
        return true;
    }
}
